/**
 * 展示返利dialog
 */
import ProTable from '@ant-design/pro-table';
import type { ProColumns } from '@ant-design/pro-table';
import { Button} from 'antd';
import { Modal } from 'antd';
import React from 'react';
import {RebateItem} from '../../model'
import request from '@/utils/request';
  
export type ChooseProps = {
    modalVisible: boolean;
    dealerId:string;
      onCancel: (flag?: boolean) => void;
  };

  
const RebateDialog: React.FC<ChooseProps> = (props)=>{
  
    function onCancel(){
      props.onCancel()
    }


    const query=async(params:any)=>{
      var data =  request('/xwyl/rebate/myRebateData?dealerId='+props.dealerId, {
        params,
      });
      return data;
    }

    const columns: ProColumns<RebateItem>[] = [
        {
          title:'选择日期',
          valueType:'dateRange',
          dataIndex: 'date',
          hideInTable:true,
        },
        {
          title:'日期',
          dataIndex: 'rebate_time',
          hideInSearch:true,
        },
        {
          title:"收入/支出",
          hideInSearch:true,
          dataIndex: 'amount',
          renderText: (val,record: RebateItem) =>
          {
            return (record.action==="add"?"+":"-")+val
          }
        },
        {
          title:'订单号',
          dataIndex: 'orderNumber',
          hideInSearch:true,
        },
      ];

    return (
        <Modal
        title="返利记录"
        width={1000}
        destroyOnClose={true}
        visible={props.modalVisible}
        onCancel={()=>{
          props.onCancel()
        }}

        footer={[
          <Button key="back" onClick={onCancel}>
            关闭
          </Button>,
        ]}

      >
        <ProTable<RebateItem>
         
          scroll={{ y: 240 }}
          toolBarRender={false}
          request={async(params, sorter, filter) => {
            if(params.date){
              params.beginDate=params.date[0];
              params.endDate=params.date[1];
              params.date=undefined;
            }
            return query({ ...params, sorter, filter }).then(res=>{
              res.data=res.data.list;
              return res;
            })
          }}
          columns={columns}
          rowKey="id"
          pagination={{
            pageSizeOptions:['20', '100', '500']
          }}
          />
      </Modal>
    );
}
export default RebateDialog;